import datetime

# 创建当前系统时间 date = '2020-12-12 18:15:25'
def current_time_str():
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# 将date = '2020-12-12 18:15:25'格式转成 2020_12_12_18_15_25
def datatime_to_sub(datetime):
    date_time = ""
    if datetime != "":
        date_time_array = datetime.split(" ")
        date = date_time_array[0].split("-")
        time = date_time_array[1].split(":")
        date_time_array = date + time
        n = len(date_time_array)
        i = 0
        for itr in date_time_array:
            i += 1
            if i < n:
                date_time += itr
                date_time += "_"
            else:
                date_time += itr

    return date_time
